

use ggez::{Context, GameResult, GameError, graphics};
// use ggez::mint::Point2;
use noise::{NoiseFn, Perlin};

pub struct State{
}

impl State{
    pub fn new() -> State {
        State{}
    }
}

impl ggez::event::EventHandler<GameError> for State {
    fn update(&mut self, _ctx: &mut Context) -> GameResult {
        Ok(())
    }
    fn draw(&mut self, ctx: &mut Context) -> GameResult {
        let mut canvas = graphics::Canvas::from_frame(ctx, graphics::Color::WHITE);

        let perlin = Perlin::new(0);

        for tx in 0..80 {
            for ty in 0..80 {
                let red_color = perlin.get([(tx as f64)*0.05 + 0.3, (ty as f64)*0.05])*0.5+0.5;
                let green_color = perlin.get([(tx as f64)*0.05, (ty as f64)*0.05])*0.5+0.5;
                let blue_color = perlin.get([(tx as f64)*0.05 - 0.3, (ty as f64)*0.05])*0.5+0.5;
                let rect = graphics::Mesh::new_rectangle(
                    ctx,
                    graphics::DrawMode::fill(),
                    graphics::Rect::new(tx as f32, ty as f32, 1.0, 1.0),
                    graphics::Color::new(red_color as f32, green_color as f32, blue_color as f32, 1.0),
                )?;
                canvas.draw(&rect, graphics::DrawParam::default());
            }
        }
        canvas.finish(ctx)?;
        Ok(())
    }
}